package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.dto.RoomReserveDto;
import com.sweet.fourtimeoa.pojo.dto.RoomsQueryDto;
import com.sweet.fourtimeoa.pojo.entity.MeetingRoomBookings;
import com.sweet.fourtimeoa.pojo.entity.MeetingRooms;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.pojo.vo.RoomVo;
import com.sweet.fourtimeoa.service.RoomService;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Tag(name = "会议室管理")
@RestController
@RequestMapping("/oa/room")
@CrossOrigin(origins = "*")
public class RoomController {
    @Autowired
    private RoomService roomService;
    @PostMapping("/getRoomByTime")
    @Operation(summary = "根据时间段获取空闲会议室")
    public Result getRoomByTime(@RequestBody PageDto<RoomsQueryDto> pageDto) {
        PageVo<MeetingRooms> Rooms = roomService.getRoomByTime(pageDto.getPageNum(),
                pageDto.getPageSize(),pageDto.getData().getStartTime(), pageDto.getData().getEndTime());
        return  Result.success(Rooms);
    }

    @PostMapping("/reserve")
    @Operation(summary = "预约会议室")
    public Result reserve(@RequestBody RoomReserveDto roomReserveDto) {
        roomService.reserve(roomReserveDto);
        return Result.success();
    }

    //根据用户id查询预约的会议室
    @PostMapping("/getRoomByUserId")
    @Operation(summary = "根据用户id查询预定的会议室")
    public Result getRoomByUserId(@RequestBody PageDto<Integer> pageDto) {
        PageVo<RoomVo> roomBookings = roomService.getRoomByUserId(pageDto);
        return Result.success(roomBookings);
    }
    //查询所有预定会议室
    @PostMapping("/getAllReserveRoom")
    @Operation(summary = "根据条件查询所有预定会议室")
    public Result getAllReserveRoom(@RequestBody PageDto<RoomsQueryDto> pageDto) {
        PageVo<RoomVo> allRoom = roomService.getAllReserveRoom(pageDto);
        return Result.success(allRoom);
    }

    @PostMapping("/cancelBooking")
    @Operation(summary = "取消预定会议室")
    public Result deleteRoom(@RequestBody ArrayList<Integer> updateIds) {
        roomService.deleteRooms(updateIds);
        return Result.success();
    }

    //获取所有房间
    @PostMapping("/getAllRoom")
    @Operation(summary = "获取所有房间")
    public Result getAllRoom(@RequestBody PageDto pageDto) {
        PageVo<MeetingRooms> allRoom = roomService.getAllRoom(pageDto);
        return Result.success(allRoom);
    }

    //根据id删除房间
    @DeleteMapping("/deleteRoom/{roomId}")
    @Operation(summary = "根据id删除房间")
    public Result deleteRoom(@PathVariable Integer roomId) {
        roomService.deleteRoomById(roomId);
        return Result.success();
    }

//   根据id获取房间信息
    @GetMapping("/getRoomById/{roomId}")
    @Operation(summary = "根据id获取房间信息")
    public Result getRoomById(@PathVariable Integer roomId) {
        MeetingRooms roomById = roomService.getRoomById(roomId);
        return Result.success(roomById);
    }
    // 修改房间信息
    @PutMapping("/updateRoom")
    @Operation(summary = "修改房间信息")
    public Result updateRoom(@RequestBody MeetingRooms meetingRooms) {
        roomService.updateRoom(meetingRooms);
        return Result.success();
    }

    //新增房间
    @PostMapping("/saveRoom")
    @Operation(summary = "新增房间")
    public Result addRoom(@RequestBody MeetingRooms meetingRooms) {
        roomService.addRoom(meetingRooms);
        return Result.success();
    }
}
